﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;

public partial class Admin_update_xoahinh : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        byte[] Buff = new byte[Request.TotalBytes];
        Request.InputStream.Read(Buff, 0, Request.TotalBytes);
        string q = Request.ContentEncoding.GetString(Buff);
        string id = Request["id"];
        string path = Server.MapPath("../Files/Khachsan/Images/" + id);
        switch (Request["loai"])
        {
            case "ks": path =Server.MapPath("../Files/Khachsan/Images/" + id); break;
            case "tour": path = Server.MapPath("../Files/Tour/Images/" + id); break;
            default: break;
        }
        if (File.Exists(path + "/" + q))
        {
            File.Delete(path + "/" + q);
            Response.Write(loadhinh(id));
            Response.End();
        }
        else
        {
            Response.Write("a$Xóa hình thất bại");
            Response.End();
        }
    }
    string loadhinh(string id)
    {
        string path = "../Files/Khachsan/Images/" + id;
        switch (Request["loai"])
        {
            case "ks": path = "../Files/Khachsan/Images/" + id; break;
            case "tour": path = "../Files/Tour/Images/" + id; break;
            default: break;
        }
        if (!Directory.Exists(Server.MapPath(path)))
        {
            Directory.CreateDirectory(Server.MapPath(path));
            return "";
        }
        string hinh = "";
        DirectoryInfo dr = new DirectoryInfo(Server.MapPath(path));
        FileInfo[] fi = dr.GetFiles();
        for (int i = 0; i < fi.Length; i++)
        {
            hinh += "<div class=\"hinh\" style=\"margin:10px 10px 10px 10px;float:left;width: 250px;height: 180px;\"><div class=\"Xoa\" style=\"text-align: right;margin-right: 14px;\"><a onclick=\"xoahinh('" + fi[i].Name + "'," + id + ",'" + Request["loai"] + "')\"><img style=\"position: absolute;\" ID=\"img" + i + "\" src=\"../Images/Testing/delete_16.png\" ToolTip=\"Xóa hình\" /></a></div><a href=\"" + path + "/" + fi[i].Name + "\" target=\"_blank\" ><img id=\"imghinh" + i + "\" style=\"width: 230px;height: 160px;padding: 10px 10px 10px 10px;border: solid 1px gray;\" src=\"" + path + "/" + fi[i].Name + "\"/></a>";
            hinh+= "</div>";
        }
        return hinh;
    }

}
